package com.ioc.business.order.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.ioc.business.order.domain.ReceiveOrder;
import com.ioc.business.order.domain.bo.receive.data.board.ReceiveDataBoardQueryBo;
import com.ioc.business.order.mapper.ReceiveOrderMapper;
import com.ioc.business.order.service.IReceiveDataBoardService;
import com.ioc.business.order.vo.receive.ReceiveOrderPageVo;
import com.ioc.business.order.vo.receive.data.board.ReceiveDataBoardPageVo;
import com.ioc.common.core.page.TableVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
public class ReceiveDataBoardServiceImpl implements IReceiveDataBoardService {

    private final ReceiveOrderMapper receiveOrderMapper;

    @Override
    public ReceiveDataBoardPageVo selectReceiveDataBoardPageList(ReceiveDataBoardQueryBo queryBo) {
        List<ReceiveOrder> result = receiveOrderMapper
                .queryReceiveDataBoardPageList(queryBo);
        List<ReceiveOrderPageVo> pageVos = new ArrayList<>(result.size());
        if (CollectionUtil.isNotEmpty(result)) {
            pageVos = buildPageVos(result);
        }
        List<ReceiveOrder> list = receiveOrderMapper
                .queryReceiveDataBoardList(queryBo);
        return new ReceiveDataBoardPageVo(new TableVo<>(result, pageVos), list);
    }

    private List<ReceiveOrderPageVo> buildPageVos(List<ReceiveOrder> records) {
        return records.stream().map(record -> {
            ReceiveOrderPageVo vo = new ReceiveOrderPageVo();
            BeanUtils.copyProperties(record, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}
